package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Api(tags ="角色管理")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<PageResponse<RoleVo>> pageroles(@RequestBody RoleDto roledto, @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        PageResponse<RoleVo> roleVos = roleService.pageroles(roledto, pageNum, pageSize);
        return ResponseResult.success(roleVos);
    }
    @PutMapping
    public ResponseResult addRole(@RequestBody RoleDto roledto){
        roleService.addRole(roledto);
        return ResponseResult.success(true);
    }
    //展示菜单
    @GetMapping("/find-checked-resources/{roleId}")
    public ResponseResult<List<String>> findCheckedroles(@PathVariable Long roleId){
        List<String> checkedResources = roleService.findCheckedroles(roleId);
        return ResponseResult.success(checkedResources);
    }
    //编辑和禁用启用
    @PatchMapping
    public ResponseResult updateroles(@RequestBody RoleDto roledto){
        roleService.updateroles(roledto);
        return ResponseResult.success(true);
    }
    //删除角色
    @DeleteMapping("/{roleIds}")
    public ResponseResult deleteRole(@PathVariable String roleIds){
        roleService.deleteRole(roleIds);
        return ResponseResult.success();
    }
    //角色下拉框
    @PostMapping("/init-roles")
    public ResponseResult<List<RoleVo>> xialakuang(){
        List<RoleVo> roleVo = roleService.xialakuang();
        return ResponseResult.success(roleVo);
    }


}
